const {
  get_others
} = require('../../Class/GetOthers.js');
const getOthers = new get_others();
// 获取当前日期
Page({
  data: {
    show: false,
    flag: false,
    nickName: '',
    from: '',
    hitokoto: '',
    serve: [{
        index: 0,
        img: '/image/user_info.png',
        title: '个人资料修改',
      }, {
        index: 1,
        img: '/image/about_us.png',
        title: '关于我们',
      }, {
        index: 2,
        img: '/image/update.png',
        title: '最新版本'
      }, {
        index: 3,
        img: '/image/kefu.png',
        title: '联系客服',
      },
      // {
      //   index:4,
      //   img:'/image/video_manage.png',
      //   title:'视频审核'
      // }
    ],
    chahua: ''
  },

  GetOneline() {
    wx.request({
      url: 'https://v1.hitokoto.cn/',
      data: {
        c: 'd',
        c: 'h',
        c: 'i',
        c: 'k',
        c: 'e',
        c: 'b',
        encode: 'json',
        charset: 'utf-8',
        min_length: 5,
        max_length: 20
      },
      method: 'Get',
      success: res => {
        var {
          from,
          hitokoto
        } = res.data
        this.setData({
          from,
          hitokoto
        })
      }
    })
  },
  GetIllustration() {
    const chahua = getOthers.Get_Illustration()
    this.setData({
      chahua
    })
  },
  Exit(e) {
    wx.navigateTo({
      url: '/pages/my/video-manage/index',
    })
  },
  showPopup() {
    this.setData({
      show: true
    })
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  GetIndex(e) {
    var id = e.currentTarget.dataset.id
    switch (id) {
      case 0:
        wx.navigateTo({
          url: '/pages/my/changeinfo/changeinfo',
        })
      case 1:
        wx.navigateTo({
          url: '/pages/my/about/about',
        })
        break
      case 2:
        this.showPopup()
        break
      case 3:
        wx.showModal({
          title: '抱歉',
          content: '在线客服平台正在维护中',
          showCancel: false
        })
        break
      case 4:
        this.Exit()
        break
    }

  },
  ClockIn() {
    // wx.navigateTo({
    //   url: '/pages/my/record/record',
    // })
    wx.showToast({
      title: '此区域暂未开发',
      icon: 'error'
    })
  },
  Collection() {
    wx.navigateTo({
      url: '/pages/my/collection/collection',
    })
  },
  GetTime(study_day){
    if(!study_day){
      study_day = []
    }
    const date = new Date();
    const dayOfWeek = (date.getDay() + 6) % 7;
    const diff = date.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1);
    const weekDates = Array.from({ length: 7 }, (_, i) => {
      const currDate = new Date(date);
      currDate.setDate(diff + i);
      const year = currDate.getFullYear();
      const month = currDate.getMonth() + 1;
      const day = currDate.getDate();
      const weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"][currDate.getDay()];
      const study = false;
      return { year, month, day, weekday , study };
    });
    weekDates.forEach(date => {
      const match = study_day.find(studyDate => (
        date.year === studyDate.year &&
        date.month === studyDate.month &&
        date.day === studyDate.day
      ));
      date.study = Boolean(match);
    });    
    this.setData({
      weekDates
    })
  },
  login() {
    wx.navigateTo({
      url: '/pages/my/changeinfo/changeinfo',
    })
  },
  onLoad(options){},
  onShow: function () {
    wx.showLoading({
      title: '数据正在加载中~',
      mask: true
    })
    this.GetOneline()
    this.GetIllustration()
    var study_day = wx.getStorageSync('study_day')
    this.GetTime(study_day)
    const userdata = wx.getStorageSync('UserData')
    this.setData({
      avatar: userdata.avatar,
      nickName: userdata.nickname
    })
    wx.hideLoading()
  },
})